import random
from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route('/schedule', methods=['POST'])
def schedule():
    req = request.get_json()
    print(req)
    
    transfers = []
    for ds in req['datasets']:
        for file in ds:
            src_rse_id = random.choice(file['rses'])
            dst_rse_id = random.choice(req['candidate_dst_rses'])
            transfer = {
                'file': file,
                'src_rse_id': src_rse_id,
                'dst_rse_id': dst_rse_id
            }
            transfers.append(transfer)
    
    return jsonify(transfers)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=9999)
